//
//  TTWebSocketManager.h
//  PPDL
//
//  Created by 王洋 on 2019/8/17.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "SRWebSocket.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger,WebSocketConnectType){
    WebSocketDefault = 0,   //初始状态,未连接,不需要重新连接
    WebSocketConnect,       //已连接
    WebSocketDisconnect     //连接后断开,需要重新连接
};

@class TTWebSocketManager;
@protocol TTWebSocketManagerDelegate <NSObject>

//已经连接上websocket的回调
- (void)webSocketDidConnectToServer;

//websocket收到了服务器返回的业务信息
- (void)webSocketManagerDidReceiveMessageWithString:(NSString *)string;

@end


@interface TTWebSocketManager : NSObject

//ws链接地址
@property (nonatomic, copy)     NSString *wsUrl;
@property (nonatomic, strong)   SRWebSocket *webSocket;
@property (nonatomic, weak)     id<TTWebSocketManagerDelegate > delegate;
@property (nonatomic, assign)   BOOL isConnect;  //是否连接
@property (nonatomic, assign)   BOOL isFinish;   //是否完成
@property (nonatomic, assign)   WebSocketConnectType connectType;
@property (nonatomic, assign)   BOOL isActivelyClose;    //用于判断是否主动关闭长连接，如果是主动断开连接，连接失败的代理中，就不用执行 重新连接方法

+ (instancetype)shared;//单例

- (void)refreshParam;
- (void)connectServer;//建立长连接
- (void)reConnectServer;//重新连接
- (void)SRWebSocketClose;//关闭长连接
- (void)sendDataToServer:(id)data;//发送数据给服务器

@end


NS_ASSUME_NONNULL_END
